<?php
require_once("Database.php");

session_start();

class Service {
	
	/** The constructor of this object. */
	function __construct() {
		
	}
	
	/**
	 * Generates a session id for the user.
	 * @param $userID The user to generate the id for.
	 * @return The generated id.
	 */
	function allocateSession($userID) {
		
		$key = session_id() . "_" . $userID;
		$_SESSION[$key] = date("Y-m-d H:i:s");
		return $key;
	}
	
	/**
	 * Terminates the current user session.
	 * @param $sessionID The id of the session to terminate.
	 */
	function terminateSession($sessionID) {
	
		unset($_SESSION[$sessionID]);
	}
	
	/**
	 * Checks if a user session is still valid.
	 * @param $sessionID The id of the session to validate.
	 */
	function validateSession($sessionID) {
		
		if(!isset($_SESSION[$sessionID])) {
			die("Session not valid.");
		}
	}
}
?>